/*   
   	 ************************************************************************
	 AUTHOR     : KEITH WESTPHAL
				: Corey Stone
     METHOD     : GROUPS
     PROCESS    : ADDS A USER TO A GROUP OR RETRIEVES THE USERID'S OF THE 
                : GROUP OR THE GROUPID'S OF THE USER
     ************************************************************************
*/

package actions;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import beans.Group;

import data.GroupsDB;

public class GroupUser extends Action 
{

@Override
protected void setURLMapping() {
	// TODO Auto-generated method stub
	
	urlMapping = "/groupuser";
	
}

@Override
protected void setupPage(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException 
{
	// TODO Auto-generated method stub
	
	
}

@Override
protected String doGet(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	// TODO Auto-generated method stub
	String url = "WEB-INF/views/content/Groups.jsp"; // set url here
	
	ArrayList<Group> groupli = new ArrayList<Group>();
	int userID = Integer.parseInt(request.getParameter("userID"));
	int groupID = Integer.parseInt(request.getParameter("groupID"));
	groupli = GroupsDB.getGroups(groupID, userID);
	
	if(groupli != null)
	{
		request.setAttribute("userli", groupli);	
	}
	
	return url;
}

@Override
protected String doPost(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException 
{
	String url = "WEB-INF/views/content/Groups.jsp"; // set url here
	
	Group usergroup =  (Group) request.getAttribute("usergroup");
	GroupsDB.addGroupUser(usergroup);
	
	return url;
}
}
